//
//  BaseTitleController.m
//  MyCloudMusic
//
//  Created by xiaolong on 2023/12/31.
//

#import "BaseTitleController.h"

@interface BaseTitleController ()

@end

@implementation BaseTitleController


- (void)initLinearLayoutSafeArea{
    [super initLinearLayoutSafeArea];
    [self initToolbar];
}


- (void)initRelativeLayoutSafeArea{
    [super initRelativeLayoutSafeArea];
    [self initToolbar];
}

- (BOOL)isAddToolBar{
    return YES;
}

- (void)initToolbar{
    if ([self isAddToolBar]) {
        [self.superHeaderContentContainer addSubview:self.toolbarView];
    }
    if([self.navigationController.childViewControllers count] != 1){
        [self addLeftImageButton:R.image.arrowLeft];
    }
}

- (void)setTitle:(NSString *)title{
    self.toolbarView.titleView.text = title;
}


- (SuperToolbarView *)toolbarView{
    if (!_toolbarView) {
        _toolbarView = [SuperToolbarView new];
    }
    return _toolbarView;
}


- (SuperToolbarView*)addLeftItem:(UIView *)data{
    [self.toolbarView.leftContainer addSubview:data];
    return self.toolbarView;
}

- (SuperToolbarView*)addRightItem:(UIView *)data{
    [self.toolbarView.rightContainer addSubview:data];
    return self.toolbarView;
}

- (SuperToolbarView*)addcontentItem:(UIView *)data{
    [self.toolbarView.centerContainer addSubview:data];
    return self.toolbarView;
}


- (void)addLeftImageButton:(UIImage *)data{
    self.leftButton = [ViewFactoryUtil buttonWithImage:data];
    [self.leftButton addTarget:self action:@selector(onLeftClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.toolbarView addLeftItem:self.leftButton];
}
- (void)addRightImageButton:(UIImage *)data{
    self.rightButton = [ViewFactoryUtil buttonWithImage:data];
    [self.rightButton addTarget:self action:@selector(onRightClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.toolbarView addRightItem:self.rightButton];
}
- (void)addRightButton:(NSString *)data{
    self.rightButton = [ViewFactoryUtil linkButton];
    [self.rightButton setTitle:data forState:UIControlStateNormal];
    [self.rightButton setTitleColor:[UIColor colorOnSurface] forState:UIControlStateNormal];
    [self.rightButton addTarget:self action:@selector(onRightClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.rightButton sizeToFit];
    [self.toolbarView addRightItem:self.rightButton];
}

- (void)onLeftClick:(QMUIButton *)send{
    
}
- (void)onRightClick:(QMUIButton *)send{
    
}

@end
